package com.homesoft.runtime.metadata.modle;

import java.util.HashMap;
import java.util.Locale;

import com.glodon.gtp.metadata.model.MultiLanguageField;
import com.homesoft.runtime.core.SystemInfo;


public class MultilingualField implements IMultilingualField {

	private HashMap<Locale, String> values = new HashMap<Locale, String>();

	/**
	 * 获取默认Locale对应的值
	 * 
	 * @return
	 */
	public String getValue() {
		return values.get(SystemInfo.getInstance().getDefaultLocale());
	}

	/**
	 * 设置默认Locale对应的值
	 * 
	 * @param value
	 */
	public void setValue(String value) {
		values.put(SystemInfo.getInstance().getDefaultLocale(), value);
	}

	/**
	 * 获取Locale对应的值
	 * 
	 * @param locale
	 * @return
	 */
	public String getValue(Locale locale) {
		return values.get(locale);
	}

	/**
	 * 设置Locale对应的值
	 * 
	 * @param locale
	 * @param value
	 */
	public void setValue(Locale locale, String value) {
		values.put(locale, value);
	}

	/**
	 * 从另一个多语言字段拷贝值
	 * 
	 * @param src 源对象
	 */
	@SuppressWarnings("unchecked")
	public void assign(IMultilingualField src) {
		this.values = (HashMap<Locale, String>) ((MultilingualField)src).values.clone();
	}
	
	public Locale[] getLocales(){
		return this.values.keySet().toArray(new Locale[]{});
	}
	public boolean isEmpty(){
		return this.values.size() == 0;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
		return this.values.toString();
	}

	/* (non-Javadoc)
	 * @see com.homesoft.runtime.metadata.modle.IMultilingualField#remove(java.util.Locale)
	 */
	@Override
	public void remove(Locale culture) {
		this.values.remove(culture);
	}

	
}
